import 'package:dash/contants/controllers.dart';
import 'package:dash/contants/style.dart';
import 'package:dash/routing/routes.dart';
import 'package:dash/widgets/cus_text.dart';
import 'package:dash/widgets/responsiveness.dart';
import 'package:dash/widgets/side_menu/side_menu_item.dart';
import 'package:flutter/material.dart';

class SideMenu extends StatelessWidget {
  const SideMenu({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final width = MediaQuery.of(context).size.width;
    return Container(
      color: light,
      child: ListView(
        children: [
          if (ResponsiveWidget.isSmallScreen(context))
            Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                SizedBox(height: 40),
                Row(
                  children: [
                    SizedBox(width: width / 48),
                    Padding(
                      padding: const EdgeInsets.only(right: 12),
                      child: Image.asset("assets/icons/logo.png"),
                    ),
                    Flexible(
                      child: CusText(
                        "Dash",
                        size: 20,
                        weight: FontWeight.bold,
                        color: active,
                      ),
                    ),
                    SizedBox(width: width / 48),
                  ],
                )
              ],
            ),
          SizedBox(height: 30),
          Divider(color: lightGrey.withOpacity(.1)),
          Column(
            mainAxisSize: MainAxisSize.min,
            children: sideMenuItemRoutes
                .map((i) => SideMenunItem(
                      i.name == authenticationPageDisplayName
                          ? "Log out"
                          : i.name,
                      onTap: () {
                        if (i.name == authenticationPageDisplayName) {
                          menuController
                              .changeActiveItemTo(overviewPageDisplayName);
                          //TODO:: go to login page
                        }
                        if (!menuController.isActive(i.name)) {
                          menuController.changeActiveItemTo(i.name);
                          navigationController.navigationTo(i.name);
                        }
                      },
                    ))
                .toList(),
          ),
        ],
      ),
    );
  }
}
